<?php  
class ControllerModuleContent extends Controller {	
    protected function index() {	
        $this->load->model('content/category');
        $this->load->model('content/content'); 		
        $this->load->model('tool/seo_url');
        
        $this->data['template'] = $this->config->get('config_template');
        
        $categories = $this->model_content_category->getCategories(0);
        reset($categories);
        $category = current($categories);
        $this->data['contents'] = array();
        $contents = $this->model_content_content->getContentsByCategoryId($category['category_id'], 'date_modified', 4);
        foreach($contents as $item){
            $text = (strlen($item['name']) > 48) ? (mb_substr($item['name'], 0, 48, 'UTF-8') . ' ...') : $item['name'];
            $date = (strtotime($item['date_modified']) - strtotime($item['date_added']) > 0) ? strtotime($item['date_modified']) : strtotime($item['date_added']);
            $this->data['contents'][] = array(
                'text' => $text,
                'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=content/item&itemid=' . $item['content_id']),
                'date' => strftime('%d.%b.%Y', $date),
            );    
        } 
        
        $this->id = 'content';
        
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/content.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/content.tpl';
        } 
        else {
            $this->template = 'default/template/module/content.tpl';
        }
        
        $this->render();
    }
}
?>